﻿@model UserManageEditModel
@{
    string UserTrueName = Model.TrueName == string.Empty ? Model.UserName : Model.TrueName;
    string passwordHTML = Html.PasswordFor(m => m.Password, htmlAttributes: new { @class = "form-control" }).ToString();
    var user = ViewData.Get<User>("user", null);
}
@Html.AntiForgeryToken()
<div class="panel">
    <div class="panel-body">
        @using (Html.BeginAjaxForm("_ChangePassword", "ControlPanel", "", FormMethod.Post, new AjaxFormOptions { OnSuccessCallBack = "ChangePasswordCallBack" }, new { @class = "tn-form-validation " }))
        {

            @Html.HiddenFor(m => m.UserId)
            <div class="form-group">
                <label class="help-block">为 @(user!=null?user.DisplayName:string.Empty) 设置密码</label>
            </div>
            <div class="form-group has-feedback" id="passwordInput">
                <label for="Password">新密码</label>
                @Html.PasswordFor(m => m.Password, htmlAttributes: new { @class = "form-control" })
                <span class="form-control-feedback"><i class="fa fa-eye-slash"></i></span>
                <input id="newpassword" type="button"  class="tn-click-eye " />
                @Html.ValidationMessageFor(m => m.Password)
            </div>
                <div class="form-group">
                    <button type="submit" class="btn btn-primary tn-btn-wp">确定</button>
                </div>
        }
    </div>
</div>

<script>
      require(['jquery','main'],function(){
          $(document).on("click","#newpassword",function myfunction() {
              //密码明文切换
                  $this = $(this);
                  var type = $("#Password").attr("type");
                  var value = $("#Password").val();
                  if (type == "text") {
                      $("#passwordInput").html('<label for="Password">新密码</label>' + '@Html.PasswordFor(m => m.Password, htmlAttributes: new { @class = "form-control" })' +
                          '<span class="form-control-feedback"><i class="fa fa-eye-slash"></i></span>\
                            <input id="newpassword" type="button"  class="tn-click-eye " />' + '@Html.ValidationMessageFor(m => m.Password)');
                      $("#Password").val(value);
                  } else {
                      $("#passwordInput").html('<label for="Password">新密码</label>' + '@Html.TextBoxFor(m => m.Password, htmlAttributes: new { @class = "form-control" })' +
                      '<span class="form-control-feedback"><i class="fa fa-eye"></i></span>\
                            <input id="newpassword" type="button"  class="tn-click-eye " />' + '@Html.ValidationMessageFor(m => m.Password)');
                      $("#Password").val(value);
                  }
          })
          })
         
</script>
